tool
class_name HpC
extends NumberC

const component_name := "HpC"

export var max_hp = 0 setget _set_max_hp
var old_hp = 0


func _ready():
	if Engine.editor_hint:
		self.name = "Node<HP>"


func add_hp(hp: int):
	old_hp = value
	value += hp
	if value > max_hp:
		value = max_hp
	_set_val(value)


func reduce_hp(hp: int):
	old_hp = value
	value -= hp
	if value < 0:
		value = 0
	_set_val(value)


func _set_max_hp(val):
	max_hp = val
	if value > max_hp:
		value = max_hp
	if _notify:
		_notify.modify_event(_id, "max_hp")
